R you serious? Teaching R programming to psych students

ECVP 2025

Meike Snijder-Steinhilber

University of Mainz

Introduction

My backgorund

Why Are We Here Today?

Goals

  • Exchange experiences, solutions, and challenges

  • Share some of my own lessons from teaching R

  • Explore possible approaches for your teaching hurdles

Limitations

  • The workshop is shaped strongly by my own experiences and by my lab’s context

  • Every course setting is unique, and your teaching style may differ from mine

  • This is the first round of this workshop

Course structure

Challenges in Teaching R

Low student motivation due to

  • Lack of intrinsic interest in learning a programming language

  • Little to no prior experience with programming

  • Unclear understanding of why this is a relevant skill

  • Expectation that it will be difficult to learn

Structural challenges

  • Students have very heterogeneous background knowledge

  • Inconsistent use of statistical software across labs and courses

  • Limited time available to teach R

  • Large number of students in each course

  • Missing resources to provide individual feedback

Getting to know each other

Please share briefly:

  • Your name, university, and current role

  • What you hope to gain from this workshop

  • One challenge (big or small) you or your lab experience when teaching R

My mindset

My current mindset for teaching

Feedback & change:

  • Refine the course each semester (step by step)

  • Try new approaches; don’t repeat what didn’t work

  • Always seek feedback (from the whole class, in presence)

  • Feedback can hurt, share your experience with others

  • Take feedback seriously, but always consider the context

    • What caused it? What can I do to improve the situation?
  • Small adjustments can make a big difference

Structure

  • Set realistic teaching goals — and stick to them

  • Recognize that seminar structure strongly shapes student mindset

  • Provide sufficient support: resources, exercises, and constructive feedback

Communication

  • Be transparent and straightforward in communication

  • You set the tone — be aware of your influence

  • When reacting to background issues, explain openly when and why

Understanding R as a language

  • Teach the basics!

  • Practice is essential

  • Core syntax rules are like grammar

  • Core function names and arguments are like vocabulary

  • Balance the skills:

    • Reading code
    • Debugging code (learning to help yourself)
    • Writing code
  • Design exercises with intention:

    • Consider ordering and required prior knowledge
    • Balance exercise types with the skills they train
    • Use small, independent exercises to introduce new concepts (one very simple, one complex)
    • Build step by step towards realistic, real-world examples

Programming means failing

“Experienced programmers don’t fail less — they just recover faster.”

  • Normalize failure: show that errors are part of learning
  • Encourage self-help strategies first
    • Read error messages carefully
    • Try small, isolated changes
  • Demonstrate the debugger and practical debugging techniques
  • Share simple, repeatable debugging tips students can use
  • Teach how to navigate the help system effectively
    • e.g., interpreting documentation
  • Point students to external resources

Increasing student motivation

  • Connect to relevance
    • Show exciting examples of what students will be able to do by the end of the course
    • Highlight how R is needed for projects, research, and the curriculum
    • Show the broader potential of R beyond statistics
    • Use diagnostic or test questions to give students with prior knowledge realistic feedback on their level
  • Make it fun
    • Use playful or surprising examples
      • e.g., art with ggplot, scatterplot dinosaurs
    • Introduce interesting themes (even fun column names can help)
  • Support motivation through feedback
    • Provide timely, constructive, and encouraging feedback

R basics

Foundations
- Variables

  • Data types

  • Comments vs. code

  • Missing values

  • Functions & arguments

  • Reading and writing data sets

Programming skills
- Flexible vs. hard coding
- Control structures (loops, if–else)
- Understand error messages - debugging skills

Working with R
- R projects
- R scripts & R Markdown
- R packages (Who writes R packages?)

base R vs dplyr

visualisations in ggplot

And THEN, what you actually want to teach … 😉

Approaches and resources

Simulate your own data sets

Tailor your data sets to exactly what you need.

Useful functions:
- rnorm() – generate normal-distributed values
- runif() – generate uniform random values
- sample() – draw random samples
- rbinom() – simulate binary outcomes
- rexp(), rgamma(), etc. – simulate from other distributions
- expand.grid() – create all combinations of factors

useful packages:

Examples: A quick data set

library(dplyr)

set.seed(42)

n <- 80
df <- tibble(
  subject = 1:n,
  age = sample(18:70, n, replace = TRUE),
  height  = rnorm(n, mean = 170, sd = 10),
  group   = sample(c("control", "treatment"), n, replace = TRUE)
) %>%
  mutate(
    score = rnorm(n, mean = ifelse(group == "treatment", 75, 70), sd = 5),
    response = rnorm(n, mean = 50, sd = 10)
  )

df %>% head()
# A tibble: 6 × 6
  subject   age height group     score response
    <int> <int>  <dbl> <chr>     <dbl>    <dbl>
1       1    66   156. control    73.0     36.2
2       2    54   174. control    77.2     70.5
3       3    18   162. control    65.0     60.2
4       4    42   184. treatment  77.3     49.7
5       5    27   166. control    70.4     57.0
6       6    53   177. control    74.5     40.3

Correlated data

library("MASS")

Attaching package: 'MASS'
The following object is masked from 'package:dplyr':

    select
set.seed(123)

# Define the mean vector
mean_vector <- c(0, 2, 1.8)

# Define the covariance matrix
cov_matrix <- matrix(c(
  1.00, 0.22, 0.10,
  0.22, 1.00, 0.80,
  0.10, 0.80, 1.00
), nrow = 3, byrow = TRUE)

# Generate n correlated random numbers
n <- 200
correlated_data <- mvrnorm(n, mu = mean_vector, Sigma = cov_matrix)

# Convert to a data frame and add column names
correlated_data <- data.frame(correlated_data)
names(correlated_data) <- c("fitness_level", "sport", "health")

# Calculate the correlations
round(cor(correlated_data), 2)
              fitness_level sport health
fitness_level          1.00  0.24   0.08
sport                  0.24  1.00   0.79
health                 0.08  0.79   1.00

Constructive Alignment

Teaching, learning, and assessment should all point in the same direction.

Intended learning outcomes
- What should students be able to do? - What specific R skills should students be able to demonstrate?
- e.g., import a dataset, run a regression, visualize results

Teaching & learning activities
- How will they practice and engage with the content? - e.g., exercises at home, debugging code from other students, projects with real data)

Assessment
- How will they demonstrate achievement of the outcomes?
- e.g., open book exams, oral explanations, …

Constructive Alignment – Background

  • Developed by John Biggs (1996)
  • Based on the idea that students construct their own learning
  • The role of the teacher: design learning environments that support this process
  • Alignment means:
    • Learning outcomes define what students should achieve
    • Teaching activities give opportunities to practice
    • Assessment measures achievement of outcomes

Alternative exams

Open-book exams
- Debug or correct given code
- Extend existing scripts with new functionality
- Explain what code does (or why it fails)
- Interpret error messages
- Use R’s help system to solve a task with a new function

Data science contest
- Students have to analyze a (simulated) data set - use personas to create variability - teaches also the meaning of QRPs & p-hacking - Students compete to produce the best talk/analysis/visualization - Students have to detect the “bad sheeps” - Encourages creativity, real-world problem-solving, and communication of results

Flipped Classroom – The Concept

  • Traditional order is reversed:
    • Students first engage with new material at home (videos, readings, tutorials)
    • Class time is used for practice, discussion, problem-solving
  • Emphasizes active learning rather than passive listening
  • Teacher role shifts from “lecturer” to facilitator/coach

Flipped Classroom – When & Why It Works

Useful when:
- Content can be learned at different paces - Class time is valuable for collaboration and feedback

Success factors: - Clear, well-structured pre-class materials
- Accountability (e.g., small quizzes, short reflections)
- In-class activities tightly linked to pre-class work

Flipped Classroom – Challenges

  • Students may be unprepared in class
  • High effort for instructors:
    • Preparing quality pre-class materials (texts, videos, exercises)
    • Designing effective in-class activities can be difficult
  • Requires a cultural shift:
    • Students expect “being taught” in class
    • Teachers must let go of content delivery
    • Teachers mus be “strict”

ChatGPT as a student

• Do not accept solutions that are outsode of what the course teached • Pick the exam well, so it becomes uninteresting to cheat

ChatGPT as a teacher

• Be as efficient as possible and focus on what matters • Make your feedback more friendly • Come up with exercises, or explanations for code

learnr

Otter as an example

Workshop

Feedback

Contact


Software:




Contact:

E-Mail: meike.steinhilber@uni-mainz.de

GitHub: MeikeSteinhilber

Homepage: https://methoden.amd.psychologie.uni-mainz.de/steinhilber/











Appendix

in the past:

  • post-hoc analyses of QRP

SPRTs: